package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.FreezeBean;

import java.text.DecimalFormat;
import java.util.List;

public class FreezeAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<FreezeBean> mFreezeBean;
    public FreezeAdapter(Context context, List<FreezeBean> maxAgentbeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mFreezeBean = maxAgentbeanDatas;
    }
    @Override
    public int getCount() {
        return mFreezeBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mFreezeBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.freeze_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.freezee_money = convertView.findViewById(R.id.freezee_money);
            viewHolder.freeze_deal = convertView.findViewById(R.id.freeze_deal);
            viewHolder.freeze_sn = convertView.findViewById(R.id.freeze_sn);
            viewHolder.freeze_kong = convertView.findViewById(R.id.freeze_kong);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        FreezeBean agentbean = mFreezeBean.get(position);
        Double a1 = Double.parseDouble(agentbean.getMoney());
        DecimalFormat decimalFormatq = new DecimalFormat("0.00");
        String b1 = decimalFormatq.format(a1);
        viewHolder.freezee_money.setText(b1+"元");

        Double a = Double.parseDouble(agentbean.getDeal());
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        String b = decimalFormat.format(a);
        viewHolder.freeze_deal.setText(b+"元");
        viewHolder.freeze_sn.setText(agentbean.getSn());

        if(position==mFreezeBean.size()){
            viewHolder.freeze_kong.setVisibility(View.GONE);
        }

         return convertView;
    }

    public static class ViewHolder{
        TextView freezee_money;
        TextView freeze_deal;
        TextView freeze_sn;
        TextView freeze_kong;

    }
}
